package com.example.demo.commons.r;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)
public class R<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;

    public static <S> R<S> succ(S data) {
        return new R<S>().setCode(Codes.SUCC.getCode()).setMsg(Codes.SUCC.getMsg()).setData(data);
    }

    public static <S> R<S> succ() {
        return succ(null);
    }

    public static <S> R<S> fail(Codes code) {
        return fail(code, null);
    }

    public static <S> R<S> fail(Codes code, S data) {
        return new R<S>().setCode(code.getCode()).setMsg(code.getMsg()).setData(data);
    }

}

